package com.vne.skyemart.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.servlet.ModelAndView;

import com.vne.skyemart.model.Brand;
import com.vne.skyemart.service.BrandService;

@Controller
@SessionAttributes
@RequestMapping("/brand")
public class BrandController {

	@Autowired
	private BrandService brandservice;

	@RequestMapping(value = "/save", method = RequestMethod.POST)
	public ModelAndView saveBrand(@ModelAttribute(" brand") Brand  brand,
			BindingResult result) {
		 brandservice.addBrand(brand);
		return new ModelAndView("redirect:/brand.html");
	}

	@RequestMapping(method = RequestMethod.GET)
	public String listBrand(Model model) {
		model.addAttribute("brand",  brandservice.listBrand());

		return "brandList";
	}

	@RequestMapping(value = "/add", method = RequestMethod.GET)
	public ModelAndView addBrand(@ModelAttribute("brand") Brand brand,
			BindingResult result) {
		return new ModelAndView("addBrand");
	}
}